package com.vvv.method;

import static java.lang.Thread.sleep;

/**
 * @author vvv
 * @date 2023-10-11 09 02
 * discription
 */
public class InterruptedDemo {


    public static void main(String[] args) throws InterruptedException{
        // 阻塞dome
        Thread t1 = new Thread(() -> {
            Thread current = Thread.currentThread();
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                System.out.println("t1 exception" + e);
                //System.out.println("interrupt后e " + current.isInterrupted());
            }
           // System.out.println("interrupt后 " + current.isInterrupted());
        }, "t1");
        t1.start();
        //t1.join();

        sleep(100);
        System.out.println("interrupt前 " + t1.isInterrupted());
        t1.interrupt();
        sleep(100);
        System.out.println("interrupt后 " + t1.isInterrupted());
        System.out.println("main is done");
        // 正常工作dome
//        Thread t1 = new Thread(() -> {
//            while (true) {
//                System.out.println("t1 still running ...");
//            }
//        }, "t1");
//        t1.start();
//        sleep(10);
//        System.out.println("=================main " + t1.isInterrupted());
//        t1.interrupt();
//        System.out.println("=================main " + t1.isInterrupted());
//        System.out.println("main is done");
    }
}
